
from sample.common.base_page import BasePage


class B2bLoginPage(BasePage):
    URL = '/#/login'

    def login(self, user, password, client_number):
        """直接账号密码登录B2B商城"""
        self.fill_input('BuyersLogin.LoginInput', user)
        self.fill_input('BuyersLogin.PasswordInput', password)
        self.screenshot()
        self.click_element('BuyersLogin.LoginBtn')
        if client_number:
            self.switch_client(client_number)

    def switch_client(self, client_number):
        """选择登录主体"""
        if self.is_element_exist('BuyersLogin.SwitchClientText'):
            self.click_element(f'BuyersLogin.ClientNum,{client_number}')

    def yaoud_login(self, user, password):
        """从药德一键跳转登录B2B商城"""
        self.navigate(self.URL)
        self.click_element('BuyersLogin.YaoudLink')
        self.fill_input('BuyersLogin.YaoudLoginInput', user)
        self.fill_input('BuyersLogin.YaoudPasswordInput', password)
        self.screenshot()
        self.click_element('BuyersLogin.YaoudLoginBtn')

    def logout(self):
        self.click_element('BuyersLogin.LogoutBtn')


